package com.bookm.bookm.controller;

import com.bookm.bookm.entity.Result;
import com.bookm.bookm.service.CollegeService;
import com.bookm.bookm.service.impl.CollegeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/*
    所有与学院表操作有关的接口在此提供
 */
@WebServlet("/college")
public class CollegeServlet extends HttpServlet {
    private CollegeService service = new CollegeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String key = req.getParameter("key");
        PrintWriter out = resp.getWriter();
        switch (key){
            // 获取学院列表
            case "getCollegeList":
                getCollegeList(out);
                break;
            // 获取专业信息列表
            case "getProfList":
                String cid = req.getParameter("cid");
                getProfList(Integer.parseInt(cid) ,out);
                break;
        }
    }
    private void getCollegeList(PrintWriter out){
        Result data = service.getCollegeList();
        out.print(data.toString());
    }
    private void getProfList(Integer cid, PrintWriter out){
        Result data = service.getProfList(cid);
        out.print(data.toString());
    }
}
